

//
//  Person.m
//  05-homework
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person
- (instancetype)initWithName:(NSString *)name age:(int)age  sex:(NSString *)sex {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}
- (NSString *)description{
    return [NSString stringWithFormat:@"姓名:%@  年龄:%d 性别:%@", _name, _age, _sex];
}
- (NSComparisonResult)compareByName:(Person *)anotherPerson {
    return [self.name compare:anotherPerson.name];
}
- (NSComparisonResult)compareByAge:(Person *)anotherPerson {
    if (self.age >= anotherPerson.age) {
        return NSOrderedAscending;
    } else if (self.age == anotherPerson.age) {
        return NSOrderedSame;
    } else {
        return NSOrderedDescending;
    }
}
- (NSComparisonResult)compareBySex:(Person *)anotherPerson {
    return [self.sex compare:anotherPerson.sex];
}



@end
